home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / AbstractDirectory.java < prev    next >
Text File  |  1998-09-24  |  4KB  |  187 lines

  1. package com.symantec.itools.io;
  2.  
  3.  
  4. import java.io.File;
  5. import java.io.FilenameFilter;
  6. import java.io.FileNotFoundException;
  7. import java.io.IOException;
  8. import java.io.FileInputStream;
  9. import java.io.FileOutputStream;
  10.  
  11.  
  12. /**
  13.  * @author Symantec Internet Tools Division
  14.  * @version 1.0
  15.  * @since VCafe 3.0
  16.  */
  17.  
  18. public class AbstractDirectory
  19.     extends Directory
  20. {
  21.     public AbstractDirectory()
  22.     {
  23.     }
  24.  
  25.     public AbstractDirectory(String dirName)
  26.         throws NotDirectoryException,
  27.                IOException
  28.     {
  29.         this(dirName, false);
  30.     }
  31.  
  32.     public AbstractDirectory(String dirName, boolean create)
  33.         throws NotDirectoryException,
  34.                IOException
  35.     {
  36.         setName(dirName, create);
  37.     }
  38.  
  39.     /**
  40.      * @param dirName TODO
  41.      * @param create TODO
  42.      * @exception com.symantec.itools.io.NotDirectoryException
  43.      * @exception java.io.FileNotFoundException
  44.      * @exception java.io.IOException
  45.      * @since VCafe 3.0
  46.      */
  47.     protected void setName(String dirName, boolean create)
  48.         throws NotDirectoryException,
  49.                FileNotFoundException,
  50.                IOException
  51.     {
  52.         name      = FileSystem.getCanonicalPath(dirName, true);
  53.         directory = new File(name);
  54.  
  55.         if(directory.exists())
  56.         {
  57.             if(!(directory.isDirectory()))
  58.             {
  59.                 throw new NotDirectoryException(name);
  60.             }
  61.         }
  62.         else
  63.         {
  64.             if(create)
  65.             {
  66.                 directory.mkdirs();
  67.             }
  68.         }
  69.     }
  70.  
  71.     /**
  72.      * @param filter TODO
  73.      * @param recurse TODO
  74.      * @since VCafe 3.0
  75.      */
  76.     public String[] listFiles(FileFilenameFilter filter, boolean recurse)
  77.     {
  78.         if(!exists())
  79.         {
  80.             return (new String[0]);
  81.         }
  82.  
  83.         return (super.list(filter, recurse));
  84.     }
  85.  
  86.     /**
  87.      * @param filter TODO
  88.      * @param recurse TODO
  89.      * @since VCafe 3.0
  90.      */
  91.     public String[] listDirectories(DirectoryFilenameFilter filter, boolean recurse)
  92.     {
  93.         if(!exists())
  94.         {
  95.             return (new String[0]);
  96.         }
  97.  
  98.         return (super.listDirectories(filter, recurse));
  99.     }
  100.  
  101.     /**
  102.      * @param filter TODO
  103.      * @param recurse TODO
  104.      * @since VCafe 3.0
  105.      */
  106.     public String[] list(FilenameFilter filter, boolean recurse)
  107.     {
  108.         if(!exists())
  109.         {
  110.             return (new String[0]);
  111.         }
  112.  
  113.         return (super.list(filter, recurse));
  114.     }
  115.  
  116.     /**
  117.      * @param filter TODO
  118.      * @param dst TODO
  119.      * @param recurse TODO
  120.      * @since VCafe 3.0
  121.      */
  122.     public boolean copyTo(FileFilenameFilter filter, Directory dst, boolean recurse)
  123.         throws IOException
  124.     {
  125.         if(!exists())
  126.         {
  127.             return (false);
  128.         }
  129.  
  130.         return (super.copyTo(filter, dst, recurse));
  131.     }
  132.  
  133.     /**
  134.      * @param dst TODO
  135.      * @param recurse TODO
  136.      * @since VCafe 3.0
  137.      */
  138.     public boolean copyTo(Directory dst, boolean recurse)
  139.         throws IOException
  140.     {
  141.         if(!exists())
  142.         {
  143.             return (false);
  144.         }
  145.  
  146.         return (super.copyTo(dst, recurse));
  147.     }
  148.  
  149.     /**
  150.      * @since VCafe 3.0
  151.      */
  152.     public boolean delete()
  153.     {
  154.         if(!exists())
  155.         {
  156.             return (false);
  157.         }
  158.  
  159.         return (super.delete());
  160.     }
  161.  
  162.     public boolean deleteAll()
  163.     {
  164.         if(!exists())
  165.         {
  166.             return (false);
  167.         }
  168.  
  169.         return (super.deleteAll());
  170.     }
  171.  
  172.     /**
  173.      * @since VCafe 3.0
  174.      */
  175.     public boolean mkdir()
  176.     {
  177.         return (directory.mkdir());
  178.     }
  179.  
  180.     /**
  181.      * @since VCafe 3.0
  182.      */
  183.     public boolean mkdirs()
  184.     {
  185.         return (directory.mkdirs());
  186.     }
  187. }